Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
Cannot use "interface" declarations from TypeScript in JS (React Native tests)

I have a ReactNative app and I am trying to write a test using Jest. My test need to use classes from a native component (react-native-nfc-manager) and a class I need is declared like this

  export interface TagEvent {
    ndefMessage: NdefRecord[];
    maxSize?: number;
    type?: string;
    techTypes?: string[];
    id?: number[];
  }

and if I try to use this definition directly like

const event = new TagEvent();

I get this error

TypeError: _reactNativeNfcManager.default is not a constructor

I am coming from Java worlds so I think to myself - of course it cannot instantiate an interface, it needs a class so I write a test instance for this interface:

class TestTagEvent implements TagEvent {
    ndefMessage: NdefRecord[] = []
    maxSize?: number;
    type?: string;
    techTypes?: string[];
    id?: number[];
}

But the problem seem to be different since it does not work either:

TypeError: _TestTagEvent.TestTagEvent is not a constructor

What am I missing?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can't construct an object using an interface. An interface is just a set of properties that can be used to define required/available properties of variables.

To use the interface to initialize a variable, you want to do this:

const eventVar: TagEvent;

If you want to use TagEvent as a instantiable object, you need to define it as a class, not an interface. Something like this, where TagEventProps is the TagEvent interface you defined:

class TagEvent {
  constructor(props: TagEventProps) {
    this.ndefMesssage = props.nDefMessage;
    //etc...
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

After further experiments problem has been solved by adding 'export' to the class. Admittedly, the original error description is absolutely not matching the root cause.

export class TestTagEvent implements TagEvent {

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda